package com.boot.rabbitmq.apidemo.model.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.util.logging.Logger;

/**
 *   原生态的rabbitmq的API操作
 */
public class ConnectionUtil {
    Logger logger = Logger.getLogger(this.getClass().getName());

    public static Connection getConnection() throws Exception {
        //定义连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //设置服务地址
        factory.setHost("127.0.0.1");
        //端口
        factory.setPort(5672);
        //设置账号信息，用户名、密码、vhost
       // factory.setVirtualHost("testhost");
        factory.setUsername("jack");
        factory.setPassword("123");
        // 通过工程获取连接
        Connection connection = factory.newConnection();
        return connection;
    }

}
